package edu.stu.mall.fragment.knowledge

import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import edu.mall.base.BaseFragment
import edu.mall.base.view.NoScrollLayoutManager
import edu.stu.mall.BR
import edu.stu.mall.R
import edu.stu.mall.adapter.CartListAdapter
import edu.stu.mall.adapter.RecommendedProductAdapter
import edu.stu.mall.databinding.FragmentKnowledgeBinding


class FragKnowledge : BaseFragment<FragmentKnowledgeBinding, FragKnowledgeViewModel>() {


    private val cartListAdapter = CartListAdapter()

    override fun getLayoutId(): Int {
        return R.layout.fragment_knowledge

    }

    override fun getViewModelId(): Int {
        return BR.knowledgeVm

    }

    override fun initViewData() {


        val layoutManager = LinearLayoutManager(context)
        binding?.rlvCart?.layoutManager = layoutManager
        binding?.rlvCart?.adapter = cartListAdapter
        viewModel?.cartListDataItem?.observe(viewLifecycleOwner) {
            cartListAdapter.setData(it)
        }
        viewModel?.isEmptyCart?.observe(viewLifecycleOwner) { isEmpty ->
            binding?.tvNull?.visibility = if (isEmpty) View.VISIBLE else View.GONE
        }
    }

}